import Taro, { Config } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { AtTabBar }  from 'taro-ui'

import MyList from '../components/my/list'
import MyHistory from '../components/my/history'
import New from '../components/my/new'

import Utils from '../utils/utils'
import Global from '../utils/global'

import './index.scss'

export default class IndexPage extends Taro.Component {
  constructor () {
    super(...arguments)
    this.state = {
      tabIndex: 0
    }
  }

  config: Config = {
    navigationBarTitleText: '报修系统'
  }

  //////////////////////////////////// Hooks ////////////////////////////////
  componentWillMount(){
    if(Global.get('token')){
      //
    }
    else{
      Taro.redirectTo({
        url:'./login/login'
      })
    }
  }

  //////////////////////////////////// Render ////////////////////////////////
  render () {
    const { tabIndex } = this.state

    const tabList = [
      { title: '跟踪', iconType: 'bell'},
      { title: '申请', iconType: 'add-circle' },
      { title: '历史', iconType: 'list'}
    ];

    return (
      <View>
        {tabIndex == 0 && <MyList />}
        {tabIndex == 1 && <New />}
        {tabIndex == 2 && <MyHistory />}
        <AtTabBar
          fixed
          tabList={tabList}
          onClick={this.tabClick.bind(this)}
          current={tabIndex}
        />
      </View>
    )
  }

  //////////////////////////////////// Events ///////////////////////////////
  private tabClick (value) {
    this.setState({
      tabIndex: value
    })
  }


}
